package com.skywaregroup.arenal;

import javax.ws.rs.*;
import javax.ws.rs.core.*;
import javax.ws.rs.core.Response.*;


/** Throw this exception to return a 401 Unauthorized response.  The WWW-Authenticate header is
 * set appropriately and a short message is included in the response entity. */
public class UnauthorizedException extends WebApplicationException
{
    private static final long serialVersionUID = 1L;

    public UnauthorizedException()
    {
        this(new ExcetionInfo(ErrorCodes.INVALID_TOKEN));
    }

    public UnauthorizedException(ExcetionInfo info)
    {
		//super(Response.status(Status.UNAUTHORIZED).header(HttpHeaders.WWW_AUTHENTICATE,
		//"Basic realm=\"" + realm + "\"")
    	//.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_XML + ";charset=utf-8")
    	super(Response.status(Status.UNAUTHORIZED)
    			.header(HttpHeaders.CACHE_CONTROL, "no-cache, no-store, must-revalidate") // HTTP 1.1.
				.header("Pragma", "no-cache") // HTTP 1.0.
				.header(HttpHeaders.EXPIRES, "0") // Proxies.
    			.type(MediaType.APPLICATION_XML + ";charset=utf-8")
    			.entity(info)
    			.build());
    }
}
